#ifndef FILETABLEMODEL_H
#define FILETABLEMODEL_H

#include <QAbstractTableModel>
#include <QtCore/QStringList>
#include <QtCore/QSize>
#include <QtCore/QDir>
#include "ImageThumbsCache.h"

//class ImgDirLoader;
class FileTableModel : public QAbstractTableModel
{
	Q_OBJECT

public:
	enum Roles {FilePathRole=Qt::UserRole+200,MarkRole=Qt::UserRole+201};

	FileTableModel(QObject *parent=0);
	virtual ~FileTableModel();
	
	QSize filePreviewSize() const{
		return _filePreviewSize;
	}
	
	void notifyFileRenamed(const QString& name,const QString& newName);
	void notifyFileRemoved(const QString& name);

	virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const override;
	virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const  override;
	virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const override; 

	void signItem(const QModelIndex&);
	void unsignItem(const QModelIndex&);
	void signAll();
	void unsignAll();
	QStringList signedFilesPaths() const;
public slots:
	void setFilePreviewSize(const QSize&);
	void setScrollViewWidth(int);
	void setRootDir(const QString& path);
	void sortByTime();
	void sortByName();
	void sortBySize();

	//void clearAllCachedImages();
private:
	void setSortFlags(QDir::SortFlags);
	QSize _filePreviewSize;
	int  _scrollViewWidth;

	//QStringList  _files;
	struct FileItem{
		FileItem():isSigned(false){}
		FileItem(const QString& fn):fileName(fn),isSigned(false){}
		QString fileName;
		bool  isSigned;
		bool operator==(const FileItem& item) const{
			return fileName==item.fileName;
		}
	};
	QList<FileItem>  _files;
	QString _currRoot;

	//QMap<QString/*rootPath*/,ImgDirLoader*> _imgDirLoaders;

	QDir::SortFlags  _currSortFlags;

	mutable ImageThumbsCache _thumbsCache;

	int fileIndexFromModelIndex(const QModelIndex&) const;
private slots:
	void onImageLoaded(const QString&);
};

#endif // FILETABLEMODEL_H
